package com.zwy.ubts.controller;

import com.yg.yws.annotation.YWebPath;
import com.yg.yws.annotation.YWebServlet;
import com.yg.yws.beans.RetType;
import com.zwy.ubts.bean.Book;
import com.zwy.ubts.bean.User;
import com.zwy.ubts.service.BookService;
import com.zwy.ubts.service.LbService;
import com.zwy.ubts.service.OrderService;
import com.zwy.ubts.service.UserService;
import com.zwy.ubts.service.impl.BookServiceImpl;
import com.zwy.ubts.service.impl.LbServiceImpl;
import com.zwy.ubts.service.impl.OrderServiceImpl;
import com.zwy.ubts.service.impl.UserServiceImpl;
import com.zwy.ubts.utils.DataInfo;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author Zhou Wenying
 * @Description:
 * @Date Created in 20:36 2023/3/7
 */
@YWebServlet
public class IndexController {

    BookService bookService = new BookServiceImpl();
    UserService userService = new UserServiceImpl();
    private OrderService orderService = new OrderServiceImpl();
    private LbService lbService = new LbServiceImpl();

   /* @YWebPath("/header")
    public RetType login(){
        return RetType.retForward(DataInfo.PAGE_ROOT+"header.jsp");
    }*/

   @YWebPath("/")
    public RetType index(){

       //从服务获取数据
       List<Book> hotbooks = bookService.selectHotBook();
       List<Book> newbooks = bookService.selectNewBook();
       List<Integer> integers = lbService.selectLb();

       List<Book> lbBook = new ArrayList<>();
       for (int i = 0; i < integers.size(); i++) {
           Book book = bookService.selectByBookId(integers.get(i));
           lbBook.add(book);
       }

       //为页面数据做准备
       Map map = new HashMap<>();
       map.put("hotbooks",hotbooks);
       map.put("newbooks",newbooks);
       map.put("lbBook",lbBook);

       //去首页并将数据传输过去
       return RetType.retForward("/index.jsp",map);
   }







}
